<template>
  <!-- 个人简历 -->
  <Top-Page>
    <view class="top">
      <cu-custom bgColor="bg-gradual-white-3" :isBack="true">
        <template #backText></template>
        <template #content>人才库</template>
        <template #right>
          <image class="more" src="../../../static/image/common/w-more.png" mode="widthFix" />
        </template>
      </cu-custom>

      <view class="user-info__wrap">
        <image class="user-img" :src="userInfo.avatar" mode="widthFix" />

        <view class="user-info">
          <view class="name">
            {{ userInfo.realname }}
          </view>
          <view class="jy">
            <view>{{ userInfo.age }}</view>
          </view>

          <view class="account">
            {{ userInfo.account }}
          </view>
        </view>
      </view>
    </view>

    <view class="content">
      <!-- 个人介绍 -->
      <view class="item">
        <view class="item-title" @click="toAmend('introduce', '个人介绍')">
          <view class="title">个人介绍</view>
          <view class="iconfont icon-m01"></view>
        </view>

        <view class="item-value">
          {{ data.introduce || "暂无" }}
        </view>
      </view>

      <!-- 求职意向 -->
      <view class="item">
        <view class="item-title" @click="toIntentionList()">
          <view class="title">求职意向</view>
          <view class="iconfont icon-m01"></view>
        </view>

        <view class="item-value intention-wrap">
          <template v-for="item in data.intention">
            <view class="intention" v-if="!!item.id">
              <view>{{ item.type }}</view>
              <view>{{ item.salary_min }}k - {{ item.salary_max }}k</view>
            </view>
          </template>
        </view>
      </view>

      <!-- 工作经历 -->
      <view class="item">
        <view class="item-title" @click="toJobexp(0, '')">
          <view class="title">工作经历</view>
          <view class="iconfont icon-m01"></view>
        </view>

        <view class="item-value job-exp-wrap">
          <view class="job-exp" v-for="item in data.job_exp" @click="toJobexp(item.id, item)">
            <view class="job-exp-composer">{{ item.company }}</view>
            <view class="job-exp-date">{{ item.start_date }}-{{ item.end_date }}</view>
            <view class="job-exp-content">
              {{ item.content }}
            </view>
          </view>
        </view>
      </view>

      <!-- 教育经历 -->
      <view class="item">
        <view class="item-title" @click="toEduexp(0, '')">
          <view class="title">教育经历</view>
          <view class="iconfont icon-m01"></view>
        </view>

        <view class="item-value job-exp-wrap">
          <view class="job-exp" v-for="item in data.edu_exp" @click="toEduexp(item.id, item)">
            <view class="job-exp-composer">{{ item.name }}</view>
            <view class="job-exp-date">{{ item.start_date }}-{{ item.end_date }}</view>
            <view class="job-exp-content">{{ item.exp }} | {{ item.major }}</view>
          </view>
        </view>
      </view>
    </view>
  </Top-Page>
</template>

<script lang="ts" setup>
import { ref, reactive } from "vue";
import recruitApi from "@/api/recruit.js"; //招聘相关API
import { onShow } from "@dcloudio/uni-app";

const data: any = ref(uni.getStorageSync("mine"));

const userInfo = uni.getStorageSync("userInfo");

onShow(() => {
  mine();
});

const toAmend = (type: string, name: string) => {
  uni.navigateTo({
    url: `/pages/recruit/amend/amend?type=${type}&name=${name}`
  });
};

//求职意向
const toIntentionList = () => {
  uni.navigateTo({
    url: "/pages/recruit/intention/intention-list"
  });
};

//工作经历
const toJobexp = (id: number, item: any) => {
  id && uni.setStorageSync("amend-toJobexp", item);

  uni.navigateTo({
    url: `/pages/recruit/jobexp/jobexp?id=${id}`
  });
};

//教育经验
const toEduexp = (id: number, item: any) => {
  id && uni.setStorageSync("amend-eduexp", item);

  uni.navigateTo({
    url: `/pages/recruit/eduexp/eduexp?id=${id}`
  });
};

function mine() {
  recruitApi.mine().then((res) => {
    uni.setStorageSync("mine", res.data);

    data.value = res.data;
  });
}
</script>

<style lang="scss" scoped>
@import "./index.scss";
</style>
